package pl.pw.gis.gc_sa.tests;

import org.junit.Test;

import pl.pw.gis.gc_sa.algo.SimulatedAnnealing;
import pl.pw.gis.gc_sa.data.Graph;
import pl.pw.gis.gc_sa.utils.Utils;

/**
 * Klasa zawierajaca testy wykonywane przy pomocy biblioteki jUnit.
 * 
 * W tej klasie testowana jest poprawnosc kolorowania grafow dla grafow bedacych
 * duzymi, pojednczymi cyklami. Dla takich grafow minimalna liczba kolorow w
 * kolorowaniu jest rowna 2 dla grafow o parzystej liczbie wierzcholkow, a 3 dla
 * grafow o nieparzystej liczbie wierzcholkow
 * 
 * @author Lukasz
 * 
 */
public class CirclesTest {
    static final int TRIES_PER_GRAPH = 50;

    String[] filenames = { "Circles\\circle4_mx.txt",
            "Circles\\circle5_mx.txt", "Circles\\circle6_mx.txt",
            "Circles\\circle10_mx.txt", "Circles\\circle15_mx.txt",
            "Circles\\circle100_mx.txt", "Circles\\circle300_mx.txt",
            "Circles\\circle301_mx.txt" };

    @Test
    public void circleTest() throws Exception {
        Utils.log("Cirles colors test. " + TRIES_PER_GRAPH + " tries per graph");
        Utils.log("--------------------");
        for (int i = 0; i < filenames.length; i++) {
            String filename = "D:/workspace/SimulatedAnnealing/bin/"
                    + filenames[i];
            Graph graph = Graph.createGraphFromFile(filename);
            Utils.log(graph.getGraphInfo());

            int min = Integer.MAX_VALUE;
            int max = 0;

            for (int t = 0; t < TRIES_PER_GRAPH; t++) {
                SimulatedAnnealing sa = new SimulatedAnnealing(graph);
                sa.start();
                sa.join();
                int noColors = sa.getMinColorCount();
                if (noColors > max) max = noColors;
                if (noColors < min) min = noColors;
            }
            Utils.log("Real best: "
                    + (graph.getVerticesCount() % 2 == 0 ? 2 : 3)
                    + " SA Min colors: " + min + " SA Max colors: " + max);
        }
    }
}
